﻿#include "testgame.h"
#include "ui_testgame.h"




TestGame::TestGame(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TestGame)
{
    ui->setupUi(this);

    setWindowTitle(QStringLiteral("TestGame"));

    cardsMaxNum = cardsHeapNum = 10;

    cardsUsedNum = cardsPlayerNum = 0;

    msgId = 0;

    for(int i = 0; i < cardsMaxNum; ++i)
        cardsHeap.append("Attack!");


    ui->cards_num->setText(QStringLiteral("当前剩余牌数：") + QString::number(cardsHeapNum));


    connect(ui->btn_gain, SIGNAL(clicked(bool)), this, SLOT(btn_gain_slot()));
    connect(ui->btn_ok, SIGNAL(clicked(bool)), this, SLOT(btn_ok_slot()));

}

void TestGame::btn_gain_slot() {

//    if(ui->listWidget_2->count()) qDebug() << ui->listWidget_2->currentItem()->text();
//    if(ui->listWidget_3->count()) qDebug() << ui->listWidget_3->currentItem()->text();


    for(int i = cardsMaxNum - cardsHeapNum; i < cardsMaxNum - cardsHeapNum + 2; ++i)
        ui->listWidget->addItem(cardsHeap[i]);

    cardsHeapNum -= 2;

    cardsPlayerNum += 2;

    ui->cards_num->setText(QStringLiteral("当前剩余牌数：") + QString::number(cardsHeapNum));


    if(ui->currCond->text().length()) ui->textEdit->append(QString::number(++msgId) + ": " + ui->currCond->text());

    ui->currCond->setText(QStringLiteral("摸牌阶段：玩家摸了两张牌！"));



}

void TestGame::btn_ok_slot() {


    if(!ui->listWidget->count()) return;

    auto item = ui->listWidget->currentItem();


    if(!item) return;

    QString txt = item->text();



    delete item;

    if(ui->currCond->text().length()) ui->textEdit->append(QString::number(++msgId) + ": " + ui->currCond->text());

    ui->currCond->setText(QStringLiteral("出牌阶段：玩家使用了") + txt + "!");
}



TestGame::~TestGame()
{
    delete ui;
}
